package com.banmoon.datastructure.ThreadBinaryTree;

public class ThreadBinaryTreeTest {

    public static void main(String[] args) {
        // 创建一个空树
        ThreadBinaryTree tree = new ThreadBinaryTree();
        // 创建根节点
        ThreadBinaryTree.ThreadTreeNode node = new ThreadBinaryTree.ThreadTreeNode(1);
        tree.setRoot(node);
        // 设置左节点
        ThreadBinaryTree.ThreadTreeNode leftNode = new ThreadBinaryTree.ThreadTreeNode(2);
        node.setLeftNode(leftNode);
        ThreadBinaryTree.ThreadTreeNode node4 = new ThreadBinaryTree.ThreadTreeNode(4);
        ThreadBinaryTree.ThreadTreeNode node5 = new ThreadBinaryTree.ThreadTreeNode(5);
        leftNode.setLeftNode(node4);
        leftNode.setRightNode(node5);
        // 设置右节点
        ThreadBinaryTree.ThreadTreeNode rightNode = new ThreadBinaryTree.ThreadTreeNode(3);
        node.setRightNode(rightNode);
        ThreadBinaryTree.ThreadTreeNode node6 = new ThreadBinaryTree.ThreadTreeNode(6);
        rightNode.setRightNode(node6);

        // 线索化二叉树
        tree.thread();
        // 查看4节点的后继节点
        System.out.println("5节点的前驱节点：" + node5.getLeftNode().getValue());
        System.out.println("5节点的后继节点：" + node5.getRightNode().getValue());
        // 查看4节点的后继节点
        System.out.println("4节点的后继节点：" + node4.getRightNode().getValue());

        // 遍历
        tree.show();


    }
}
